package yxy.game.pm2.command.plainsCraft;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.FormatMessage;
import yxy.game.pm2.message.PlainsCraftMessage;
import yxy.game.pm2.module.plainsCraft.PlainsCraftHandle;

import java.util.List;

/**
 * 中原争霸 中原争霸设置阵容
 */
@MessageType(proto = Command.PlainsCraftFormat, classtype = PlainsCraftMessage.PlainsCraftFormatRequest.class)
public class CMD_PlainsCraftFormat extends Command<PlainsCraftMessage.PlainsCraftFormatRequest> {

    @Override
    public void execute(MessageSource messageSource, PlainsCraftMessage.PlainsCraftFormatRequest request) {
        String playerCode = messageSource.getTag();
        List<FormatMessage.Format> formatList = request.getFormatList();

        PlainsCraftMessage.PlainsCraftFormatResponse.Builder response = PlainsCraftMessage.PlainsCraftFormatResponse.newBuilder();

        Result result = new PlainsCraftHandle().formatSet(playerCode, formatList, response);

        send(messageSource, response, result);

    }

    private void send(MessageSource messageSource, PlainsCraftMessage.PlainsCraftFormatResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}